class BwtNativeAdData {
  /// 标题
  final String? title;

  /// 描述
  final String? desc;

  /// 封面大图
  final String? imageUrl;

  /// 图片列表
  final List<String>? imageUrlAry;

  /// icon图片
  final String? iconImageUrl;

  BwtNativeAdData({
    this.title,
    this.desc,
    this.imageUrl,
    this.imageUrlAry,
    this.iconImageUrl,
  });

  /// 从Map创建BwtNativeAdData实例
  factory BwtNativeAdData.fromMap(Map<String, dynamic> map) {
    try {
      return BwtNativeAdData(
        title: map['title'] as String?,
        desc: map['desc'] as String?,
        imageUrl: map['imageUrl'] as String?,
        imageUrlAry: _parseImageUrlAry(map['imageUrlAry']),
        iconImageUrl: map['iconImageUrl'] as String?,
      );
    } catch (e) {
      print('Error parsing BwtNativeAdData: $e');
      rethrow;
    }
  }

  /// 解析imageUrlAry字段
  static List<String>? _parseImageUrlAry(dynamic imageUrlAry) {
    if (imageUrlAry == null) return null;

    if (imageUrlAry is List) {
      return imageUrlAry.map((item) {
        if (item is String) return item;
        return item.toString();
      }).toList();
    }

    return null;
  }

  /// 转换为Map
  Map<String, dynamic> toMap() {
    return {
      'title': title,
      'desc': desc,
      'imageUrl': imageUrl,
      'imageUrlAry': imageUrlAry,
      'iconImageUrl': iconImageUrl,
    };
  }

  /// 复制实例
  BwtNativeAdData copyWith({
    String? title,
    String? desc,
    String? imageUrl,
    List<String>? imageUrlAry,
    String? iconImageUrl,
  }) {
    return BwtNativeAdData(
      title: title ?? this.title,
      desc: desc ?? this.desc,
      imageUrl: imageUrl ?? this.imageUrl,
      imageUrlAry: imageUrlAry ?? this.imageUrlAry,
      iconImageUrl: iconImageUrl ?? this.iconImageUrl,
    );
  }

}